package com.jz.community.moduleexpress.express.ui;

import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.TextView;

import com.jz.community.basecomm.base.BaseMvpActivity;
import com.jz.community.basecomm.mvp.BaseMvpPresenter;
import com.jz.community.basecomm.utils.BaseImageLoaderUtils;
import com.jz.community.basecomm.utils.RxDataTool;
import com.jz.community.moduleexpress.R;
import com.jz.community.moduleexpress.express.info.ExpressInfoBean;

public class PackageDetailActivity extends BaseMvpActivity {
    private TextView tvTitle, tvExpressCompanyName, tvGetCode, tvExpressCode, tvServerName;
    private ImageView ivCompanyLogo, tvBack, iv_sign_logo;
    private WebView packageDetailWebView;
    private ExpressInfoBean info;
    private String url;

    @Override
    protected void initDatas() {
        super.initDatas();
        info = (ExpressInfoBean) getIntent().getSerializableExtra("data");
        url = getIntent().getStringExtra("url");

        if (null != info) {
            if (!RxDataTool.isNullString(info.getCompany().getIcon())) {
                BaseImageLoaderUtils.getInstance().loadDefaltImage(this,ivCompanyLogo,info.getCompany().getIcon());
            }
            if (!RxDataTool.isNullString(info.getCompany().getName())) {
                tvExpressCompanyName.setText(info.getCompany().getName());
            }
            if (Integer.parseInt(info.getSign_code()) > 0 && !RxDataTool.isNullString(info.getIs_sign()) && "0".equals(info.getIs_sign())) {
                tvGetCode.setText("提货码:" + info.getSign_code());
            } else {
                tvGetCode.setVisibility(View.GONE);
                iv_sign_logo.setVisibility(View.VISIBLE);
            }
            if (!RxDataTool.isNullString(info.getCode())) {
                tvExpressCode.setText("运单号:" + info.getCode());
            } else {
                tvExpressCode.setText("运单号: 暂无");
            }
            if (!RxDataTool.isNullString(info.getSpu_name())) {
                tvServerName.setText("代收点:" + info.getSpu_name());
            } else {
                tvServerName.setText("代收点: 暂无地址");
            }
        }
    }

    @Override
    protected int getContentView() {
        return R.layout.module_express_activity_package_detail;
    }

    @Override
    protected void initView() {
        tvTitle.setText("包裹详情");
        url = getIntent().getStringExtra("url");
        tvTitle =  findViewById(R.id.tv_title);
        tvBack =  findViewById(R.id.tv_back);
        ivCompanyLogo =  findViewById(R.id.iv_company_logo);
        iv_sign_logo =  findViewById(R.id.iv_sign_logo);
        packageDetailWebView = findViewById(R.id.package_detail_web_view);
        tvExpressCompanyName =  findViewById(R.id.tv_express_company_name);
        tvGetCode =  findViewById(R.id.tv_get_code);
        tvExpressCode =  findViewById(R.id.tv_express_code);
        tvServerName =  findViewById(R.id.tv_server_name);
        WebSettings webSettings = packageDetailWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);//支持js
        webSettings.setDefaultTextEncodingName("utf-8");// 编码方式
        webSettings.setSupportZoom(true);
        webSettings.setUseWideViewPort(true); //将图片调整到适合webview的大小
        webSettings.setLoadWithOverviewMode(true); // 缩放至屏幕的大小

        if (!RxDataTool.isNullString(url)) {
            packageDetailWebView.loadUrl(url);
        }
        tvBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    @Override
    protected BaseMvpPresenter createPresenter() {
        return null;
    }
}
